#pragma once
#include <list>
#include <string>
#include "JFile.h"
#include <iostream>
#include "JSerialize.h"
#include "JWorkingCopiesBaseFile.h"
#include "JOperateFileResult.h"

class JWorkingCopies : public JSerialize
{
public:
	JWorkingCopies(); 
	~JWorkingCopies(void);
	std::string CreateWorkingCopies(std::string rootUrl,std::string author,std::string password,std::string _fullPath);
	JOperateFileResult FileStatus(std::string fileName);
	JOperateFileResult AddFile(std::string fileName,bool isRecurse);
	JOperateFileResult DeleteFile(std::string fileName);
	JOperateFileResult ModifyFile(std::string oldFileName,std::string newFileName);
	//bool IsInWorkingCopies(std::string fileName);
	bool IsInSubWorkingPath(std::string fullFileName);
	//std::list<std::string> GetAllFileNames();
	int Serialize(std::iostream& _strea,int& allSize);
	void ReSerialize(std::iostream& strea);
	int SerializeWithFile(std::iostream& _strea,int& allSize);

	//return root path. If it isn't a working child path, return empty string.
private:
	bool IsBaseFileValidate(std::string _fullFileName);
	JOperateFileResult AddFile(std::list<std::string> _fullFileNames);
	bool IsChanged;
	bool needInitOperation;
	void BasicOperateInit(std::string currentWorkingPath);
	static std::string ConvertFullFileName(std::string _fileName);
	std::string ConvertToFullWorkingFileName(std::string _fullFileName);
	bool IsInWorkingPath(std::string _fileName);
	static std::string FindRootDir(std::string currentWorkingPath);
	std::list<std::list<JWorkingCopiesBaseFile>::iterator > FileInPath(std::string _filePath);
	std::string jsvnPath;
	std::string jsvnFileName;
	//Need Serialize begin.
	std::string rootUrl;
	std::string author;
	std::string password;
	std::string rootDir;
	std::list<JWorkingCopiesBaseFile> copiesFile;



	//std::list<std::string> copiesFileName;
	//Need Serialize end.
	void CreateWorkingCopiesDir();
	void CreateWorkingCopiesFile();
	void SaveWorkingCopiesToFile();
};

